<div id="tb<?php echo $uniqid;?>" style="padding:5px">
    <table cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
            <td><a href="javascript:void(0);" onclick="pagesAdd();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-tianjia1"></i><span class="l-btn-text">增加</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="pagesEdit();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span class="l-btn-text">编辑</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="pagesDelete();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shanchu"></i><span class="l-btn-text">删除</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="pagesReload();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
            <td>&nbsp&nbsp;<input id="pagesKeywords" style="width:300px" type="text" placeholder="请输入ID或标题"
                                  class="easyui-input textbox"></td>
            <td><a href="javascript:void(0);" onclick="pagesSearch();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
        </tr>
        </tbody>
    </table>
</div>
<div class="con"  style="-moz-user-select:none;">
    <table id="pages"></table>
</div>
<div id="pagesDlg" class="easyui-dialog" style="width:1040px; height:640px;" title="信息框" closed="true"></div>
<script>
    var pagesAdd = function () {
        $("#pagesDlg").dialog({
            title: '新增信息',
            closed: false,
            width: 1040,
            height: 680,
            cache: false,
            href: '/admin/pages/add',
            modal: true,
            buttons: [{
                text: '保存',
                id: 'pagessubmit',
                iconCls: 'icon-ok',
            }, {
                text: '关闭',
                iconCls: 'icon-no',
                handler: function () {
                    $("#pagesDlg").dialog('close');
                }
            }]
        });
    };
    var pagesEdit = function () {
        var row = $('#pages').datagrid('getSelected');
        if (row) {
            $("#pagesDlg").dialog({
                title: '编辑信息',
                closed: false,
                width: 1040,
                height: 680,
                cache: false,
                href: '/admin/pages/edit?id=' + row.id,
                modal: true,
                buttons: [{
                    text: '保存',
                    id: 'pagessubmit',
                    iconCls: 'icon-ok',
                }, {
                    text: '关闭',
                    iconCls: 'icon-no',
                    handler: function () {
                        $("#pagesDlg").dialog('close');
                    }
                }]
            });
        } else {
            $.messager.alert('提示', '请先选择要编辑的行！', 'warning');
        }
    };
    var pagesDelete = function () {
        var row = $('#pages').datagrid('getSelected');
        if (row) {
            $.messager.confirm('提示', '确定删除吗？', function (r) {
                if (r) {
                    $.messager.progress();
                    $.post('/admin/pages/delete', {id: row.id}, function (data) {
                        $.messager.progress('close');
                        if (data.ret == 0) {
                            $.messager.show({
                                title: '提示',
                                msg: data.msg,
                                timeout: 3000,
                                showType: 'slide'
                            });
                            pagesreload();
                        } else {
                            $.messager.alert('提示', data.msg, 'warning');
                        }
                    }, 'json');
                }
            });
        } else {
            $.messager.alert('提示', '请先选择要删除的行！', 'warning');
        }
    };
    var pagesReload = function () {
        $("#pages").datagrid('reload');
    };
    var pagesSearch = function () {
        var height = $(window).height() - $(".top").height() - 46;
        var width = $(window).width() - $(".leftmenu").width() - 8;
        $("#pages").datagrid({
            title: '页面管理',
            width: width,
            height: height,//高度
            singleSelect: true,//如果为true，则只允许选择一行
            striped: true,//是否显示斑马线效果。
            rownumbers: false,//如果为true，则显示一个行号列。
            pagination: true,//是否显示分页
            pageSize: 10,
            pageList: [10, 15, 20, 25],
            method: 'post',
            sortName: 'id',
            sortOrder: 'desc',
            idField: 'id',
            treeField: 'title',
            url: '/admin/pages/index',
            queryParams: {keywords: $('#pagesKeywords').val()},
            fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
            selectOnCheck: false,
            checkOnSelect: true,
            toolbar: '#tb<?php echo $uniqid;?>',
            columns: [[
                {field: 'id', title: 'ID', width: fixWidth(3)},
                {field: 'title', title: '标题', width: fixWidth(30)},
                {field: 'keywords', title: '描述', width: fixWidth(20)},
                {field: 'status', title: '状态', width: fixWidth(20), formatter(value, rowData, rowIndex){
                        return value===1 ? '显示' : '隐藏';
                    }},
                {field: 'created_at', title: '创建时间', width: fixWidth(20)},
            ]],
            onDblClickRow: function (index, field) {
                pagesEdit();
            }
        });
    };
    onDatagridResize("#pages");
    pagesSearch();
</script>
